import fnmatch
import gzip
import os


def get_find(filepat, top):
    for path, dirlist, filelist in os.walk(top): # os.walk，返回路径、文件夹列表、文件列表 ，且为可迭代类型，从文件夹中取一个文件做递归
        for name in fnmatch.filter(filelist, filepat): # fnmatch.filter(['1','2.py'],'*.*')，返回为['2.py']
            yield os.path.join(path,name)

def get_opener(filenames):
    for filename in filenames:
        if filename.endswith('.gz'):
            f = gzip.open(filename,'rt')